package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import com.itheima.service.DeptService;
import com.itheima.service.impl.ClazzServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;
    /**
     * 添加分页

     * @return
     */
    /*@GetMapping
    public Result list(Clazz clazz, Integer page, Integer pageSize){
        //1. 调用deptService
        List<Clazz> classtList = clazzService.selectAll(clazz,page,pageSize);
        //2. 响应数据
        return Result.success(new PageBean(10l,classtList));
    }*/
    @GetMapping
    public Result list(ClazzQueryParam clazzQueryParam){
        PageBean pageBean = clazzService.page(clazzQueryParam);
        return Result.success(pageBean);
    }

    /**
     * 添加班级
     */

    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }
    /**
     * 根据ID删除班级
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        System.out.println("根据ID删除删除班级信息: " + id);
        //接收到参数后调用service的delete方法接收看接口文档是否有返回值 （增删改一般没有返回值）
        clazzService.delete(id);
        return Result.success();
    }
    /**
     * 该接口用于根据主键ID查询班级的信息
     */
    @GetMapping("/{id}")
    public Result getByid(@PathVariable Integer id){
        System.out.println("根据ID查询班级：" + id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

    /**
     * 该接口用于修改班级的数据信息
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        System.out.println("修改班级信息" + clazz);
        clazzService.update(clazz);
        return Result.success();
    }
    /**
     * 查询所有班级
     */
    @GetMapping("/list")
    public Result selectAll(){
        List<Clazz> studentList = clazzService.selectAll();
        return Result.success(studentList);
    }

}
